<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>18.1.BOM-location对象-练习1：跳转页面</title>
</head>
<!-- 5秒自动跳转页面 -->
<!-- 1.利用定时器做倒计时效果 -->
<!-- 时间到了，就跳转页面，使用location.href -->

<body>
    <div></div>
    <script>
        var div = document.querySelector('div');
        var timer = 5;
        seconds();
        setInterval(seconds, 1000);
        function seconds() {
            if (timer == 0) {
                location.href = 'http://www.baidu.com';
            } else {
                div.innerHTML = '您将在' + timer + '秒之后跳转到首页';
                timer--;
            }
        }
    </script>
</body>

</html>